home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / logins / prefer / prefer.c next >
Text File  |  1996-07-10  |  8KB  |  224 lines

  1. /* PREFER.C
  2.  
  3.    Revised to return DOS errorlevels...
  4.    Revised to set local clock to preferred server's time...
  5.    Compiled with TURBO C.
  6.  
  7.    +-------------------------------------------------------------------+
  8.    | PREFER is a simple program that can be copied to the              |
  9.    | workstation's network driver subdirectory and included in the     |
  10.    | AUTOEXEC.BAT file immediately after NET3 is executed. PREFER      |
  11.    | breaks ALL connections with the server that NET3 attaches to and  |
  12.    | establishes new connections with a user specified server. From    |
  13.    | that point on the login directory, login utilities, and all       |
  14.    | dependent connections are from the desired server.                |
  15.    |                                                                   |
  16.    | Exception:                                                        |
  17.    |                                                                   |
  18.    | If it is the user's intention to ATTACH to other servers after    |
  19.    | logging in, dependent connections will be established to that     |
  20.    | server until it is logged out.                                    |
  21.    |                                                                   |
  22.    | Operation:                                                        |
  23.    |                                                                   |
  24.    | PREFER is simply used by entering the command "PREFER servername" |
  25.    | at the prompt or within a batch file, where "servername" is the   |
  26.    | user's desired server.                                            |
  27.    |                                                                   |
  28.    | If PREFER is invoked without a server name it will do nothing and |
  29.    | return to the DOS prompt.                                         |
  30.    |                                                                   |
  31.    | If PREFER is invoked with a server name where the dependent       |
  32.    | connections are already established, it will indicate such and    |
  33.    | return to the DOS prompt.                                         |
  34.    |                                                                   |
  35.    | If PREFER is invoked after the user has logged in, and the new    |
  36.    | server name is different from the old server name, the user will  |
  37.    | be logged out of the old server when the new connections are      |
  38.    | established.                                                      |
  39.    |                                                                   |
  40.    | The prefer program file is PREFER.EXE. It can be invoked at the   |
  41.    | command line or in a batch file, but cannot be invoked from a     |
  42.    | system or user login script.                                      |
  43.    |                                                                   |
  44.    |                       AAC Associates                              |
  45.    |                      (703) 415 - 4400                             |
  46.    |-------------------------------------------------------------------|
  47.    | NEW RELEASE "PREFER II" now includes fixes for multiple           |
  48.    | erroneous attachments, and conditions causing the primary server  |
  49.    | connection ID to be "0".                                          |
  50.    |                                                                   |
  51.    | If you run certain older LOGIN revs. and don't do a complete      |
  52.    | login, the program will leave you attached to the server at       |
  53.    | that connection ID. If you do this 8 times to 8 different servers |
  54.    | you will fill your 8 connection ID slots and not be able to       |
  55.    | to another server to login. The older version PREFER would not    |
  56.    | take into account these multiple attachments in the connection    |
  57.    | ID table and would leave them there. PREFER II clears any and     |
  58.    | all additional attachments.                                       |
  59.    |                                                                   |
  60.    | If you login to a file server and make a mistake while logging    |
  61.    | in, the program will set the Primary Connection ID to "0". This   |
  62.    | created an error condition in the earlier version of PREFER that  |
  63.    | would cause the workstation shell to loose all connections and    |
  64.    | error out. PREFER II corrects for this.                           |
  65.    |                                       |
  66.    | PREFER II by Dan Smith     9-5-90                                 |
  67.    +-------------------------------------------------------------------+
  68.  
  69. */
  70.  
  71. #include <stdio.h>
  72. #include <dos.h>
  73. #include <string.h>
  74. #include <nit.h>
  75. #include <niterror.h>
  76.  
  77. main(argc,argv)
  78. int argc;
  79. char *argv[];
  80. {
  81. void ttime(void);
  82. void primary(void);
  83. char serverName[48];
  84. WORD     connectID1,
  85.     connectID2,
  86.     DefaultID,
  87.     PrimaryID;
  88. int netReturn,localDrives;
  89. char fileServerName[48];
  90. char newDirHandle, mask;
  91. char loginPath[]="SYS:LOGIN";
  92. char letter,chr='A';
  93.  
  94. printf ("\nPREFER 2.1 By AAC Associates, Inc.\n");
  95.  
  96. if(argc<2)
  97.     {
  98.     printf("\nSyntax: PREFER servername\n\n");
  99.     printf("Errorlevels returned: \n\n");
  100.     printf("  0 - Success. Now attached to target server as the primary server.\n");
  101.     printf("  1 - Already attached to target server as the primary server.\n");
  102.     printf("  2 - Error attaching to the target server.\n");
  103.     printf("  3 - Unknown file server was requested.\n");
  104.     printf("  4 - No target server named specified on command line.\n\n");
  105.     exit(4);
  106.     }
  107.  
  108.   if (strlen(argv[1]) > 47)         /* hangs machine if this is the case */
  109.     argv[1][47] = '\0';
  110.  
  111.  
  112. strcpy(serverName,argv[1]);
  113. strupr(serverName);
  114.  
  115.  
  116. PrimaryID=GetPrimaryConnectionID();
  117. DefaultID=GetDefaultConnectionID();
  118. if(PrimaryID == 0)
  119.         {
  120.         SetPrimaryConnectionID(DefaultID);
  121.         PrimaryID = DefaultID;
  122.         }
  123. GetFileServerName(PrimaryID,fileServerName);
  124. printf("\nPrimary server is %s.\n",fileServerName);
  125.  
  126. netReturn=AttachToFileServer(&serverName, &connectID1);
  127.  
  128. switch (netReturn) {
  129.     case 0   : break;
  130.     case 248 : if (PrimaryID == connectID1)
  131.             {
  132.             printf("Already attached to server.\n");
  133.             primary();
  134.             printf("All other connections cleared.\n");
  135.             exit(1);
  136.             }
  137.         break;
  138.     case 249 : printf("No free connection slots.\n");
  139.                exit(2);
  140.                break;
  141.     case 250 : printf("No more server slots.\n");
  142.                exit(2);
  143.                break;
  144.     case 252 : printf("Unknown file server requested: %s.\n",serverName);
  145.                exit(3);
  146.                break;
  147.     case 254 : printf("Server bindery locked.\n");
  148.                exit(2);
  149.                break;
  150.     case 255 : printf("No response from server.\n");
  151.                exit(2);
  152.                break;
  153.     default  : printf("Unknown error returned.\n",netReturn);
  154.                exit(2);
  155.                break;
  156.     }
  157.  
  158.     primary();
  159.  
  160.     AttachToFileServer(&serverName, &connectID1);
  161.     SetPrimaryConnectionID(connectID1);
  162.     DetachFromFileServer(PrimaryID);
  163.  
  164.     ttime();
  165.  
  166.     localDrives=GetNumberOfLocalDrives();
  167.         letter=(char)(chr+localDrives);
  168.  
  169.     netReturn=AllocPermanentDirectoryHandle(0x00,&loginPath,letter,newDirHandle,mask);
  170.  
  171.     printf("New primary server is %s.\n",serverName);
  172.     printf("All other connections cleared.\n");
  173.     exit(0);
  174.  
  175. }
  176.  
  177. void    ttime(void)
  178.  
  179. {
  180. char dateTime[7];
  181. union    REGS regs;
  182.  
  183.     GetFileServerDateAndTime(&dateTime);
  184.     if (dateTime[0] < 80) regs.x.cx = dateTime[0] + 2000;
  185.         else    regs.x.cx = dateTime[0] +1900;
  186.         regs.h.dh = dateTime[1];
  187.         regs.h.dl = dateTime[2];
  188.         regs.h.ah = 0x2b;
  189.         int86(0x21, ®s, ®s);
  190.         regs.h.ch = dateTime[3];
  191.         regs.h.cl = dateTime[4];
  192.         regs.h.dh = dateTime[5];
  193.         regs.h.ah = 0x2d;
  194.         int86(0x21, ®s, ®s);
  195. }
  196.  
  197. void primary(void)
  198. {
  199.  
  200. WORD PrimaryID,ID;
  201. int IDtest;
  202.  
  203. PrimaryID=GetPrimaryConnectionID();
  204.  
  205. /*______________________________________________*/
  206. /*    Loop to test all eight connection ID's    */
  207. /*----------------------------------------------*/
  208.  
  209. for(ID=1;ID<=8;++ID)
  210.     {
  211.  
  212.     IDtest=IsConnectionIDInUse(ID);
  213.  
  214.     if(IDtest)
  215.         {
  216.             if(ID != PrimaryID)
  217.                 {
  218.                 DetachFromFileServer(ID);
  219.                 }
  220.         }
  221.  
  222.     }
  223.  
  224. }